

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/images/common/favicon.png">
  <link rel="icon" href="/images/common/favicon.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="Robbin">
  <meta name="keywords" content="">
  
    <meta name="description" content="今天在项目中遇到一个问题，需要 v-if 渲染的 el-form-item 组件使用 prop 设置规则校验时不生效：   发现问题：校验规则不生效el-form-item 组件使用 prop 设置规则校验时不生效 贴个没解决前的 gif 然后我尝试把注册页面改成默认展示,发现该问题不存在 解决办法给该 el-form-item 设置一个 key 即可 12345678910111213141">
<meta property="og:type" content="article">
<meta property="og:title" content="element-ui表单验证遇到v-if时不生效">
<meta property="og:url" content="http://example.com/2022/03/28/article-12/index.html">
<meta property="og:site_name" content="前端阿开">
<meta property="og:description" content="今天在项目中遇到一个问题，需要 v-if 渲染的 el-form-item 组件使用 prop 设置规则校验时不生效：   发现问题：校验规则不生效el-form-item 组件使用 prop 设置规则校验时不生效 贴个没解决前的 gif 然后我尝试把注册页面改成默认展示,发现该问题不存在 解决办法给该 el-form-item 设置一个 key 即可 12345678910111213141">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://example.com/images/common/vue.jpeg">
<meta property="article:published_time" content="2022-03-28T03:53:46.000Z">
<meta property="article:modified_time" content="2022-03-28T03:53:46.000Z">
<meta property="article:author" content="web_akai">
<meta property="article:tag" content="#Vue.js">
<meta property="article:tag" content="#ElementUI">
<meta property="article:tag" content="#v-if">
<meta property="article:tag" content="#el-form-item">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="http://example.com/images/common/vue.jpeg">
  
  
  <title>element-ui表单验证遇到v-if时不生效 - 前端阿开</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4/github-markdown.min.css" />
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hint.css@2/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10/styles/github-gist.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.css" />
  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.8.14","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":true,"baidu":"b2ef8b4e438bfbfa9667837d1124fb6c","google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":"A6A3KekcB19LfYQfObiJlDAu-gzGzoHsz","app_key":"h5J0Jt6wCaR3HtH5I0brXmRk","server_url":null,"path":"window.location.pathname","ignore_local":true}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 6.0.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>前端阿开</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/message/">
                <i class="iconfont icon-medium-fill"></i>
                留言板
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" href="javascript:;" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-books"></i>
                文档
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/">
                    
                    主题博客
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/docs/guide/">
                    
                    配置指南
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" target="_blank" rel="noopener" href="https://hexo.fluid-dev.com/docs/icon/">
                    
                    图标用法
                  </a>
                
              </div>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/images/common/default_index_img.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h2" id="subtitle" title="element-ui表单验证遇到v-if时不生效">
              
            </span>

            
              <div class="mt-3">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-author" aria-hidden="true"></i>
      Robbin
    </span>
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2022-03-28 11:53" pubdate>
        2022-03-28, 11:53
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      3.7k 字
    </span>
  

  
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      31 分钟
    </span>
  

  
  
    
      <!-- LeanCloud 统计文章PV -->
      <span id="leancloud-page-views-container" class="post-meta" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="leancloud-page-views"></span> 次
      </span>
    
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">element-ui表单验证遇到v-if时不生效</h1>
            
              <p class="note note-info">
                
                  本文最后更新于：2 年前
                
              </p>
            
            <div class="markdown-body">
              <p><img src="/./images/90711640-23CD-478f-B5C9-2089D716075A.png" srcset="/img/loading.gif" lazyload alt="注册功能"><br><img src="/./images/90711640-23CD-478f-B5C9-2089D716075B.png" srcset="/img/loading.gif" lazyload alt="注册功能"></p>
<p class="note note-success"> 今天在项目中遇到一个问题，需要 v-if 渲染的 el-form-item 组件使用 prop 设置规则校验时不生效：
</p>

<h3 id="发现问题：校验规则不生效"><a href="#发现问题：校验规则不生效" class="headerlink" title="发现问题：校验规则不生效"></a>发现问题：校验规则不生效</h3><p><code>el-form-item</code> 组件使用 <code>prop</code> 设置规则校验时不生效</p>
<p>贴个没解决前的 gif<br><img src="/./images/90711640-23CD-478f-B5C9-2089D716075C.gif" srcset="/img/loading.gif" lazyload alt="注册功能"></p>
<p>然后我尝试把注册页面改成默认展示,发现该问题不存在<br><img src="/./images/90711640-23CD-478f-B5C9-2089D716075D.gif" srcset="/img/loading.gif" lazyload alt="注册功能"></p>
<h3 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h3><p>给该 <code>el-form-item</code> 设置一个 <code>key</code> 即可</p>
<figure class="highlight html"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs html"><span class="hljs-tag">&lt;<span class="hljs-name">template</span>&gt;</span><br>  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;login-register&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;contain&quot;</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;login-box&quot;</span> <span class="hljs-attr">:class</span>=<span class="hljs-string">&quot;&#123; active: isLogin &#125;&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;login-contain&quot;</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;isLogin&quot;</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>登录<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">el-form</span></span><br><span class="hljs-tag">            <span class="hljs-attr">:model</span>=<span class="hljs-string">&quot;loginForm&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">status-icon</span></span><br><span class="hljs-tag">            <span class="hljs-attr">:rules</span>=<span class="hljs-string">&quot;rules&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;loginForm&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">label-width</span>=<span class="hljs-string">&quot;100px&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;login-form&quot;</span></span><br><span class="hljs-tag">          &gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;账号&quot;</span> <span class="hljs-attr">prop</span>=<span class="hljs-string">&quot;username&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-input</span> <span class="hljs-attr">v-model.number</span>=<span class="hljs-string">&quot;loginForm.username&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">el-input</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;密码&quot;</span> <span class="hljs-attr">prop</span>=<span class="hljs-string">&quot;password&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-input</span></span><br><span class="hljs-tag">                <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;password&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">v-model</span>=<span class="hljs-string">&quot;loginForm.password&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">autocomplete</span>=<span class="hljs-string">&quot;off&quot;</span></span><br><span class="hljs-tag">              &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">el-input</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span></span><br><span class="hljs-tag">              &gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;text&quot;</span>&gt;</span>忘记密码?<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span>&lt;/el-form-item<br>            &gt;<br><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;text-align: center&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span></span><br><span class="hljs-tag">                <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 40%&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;primary&quot;</span></span><br><span class="hljs-tag">                @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;submitForm(&#x27;loginForm&#x27;)&quot;</span></span><br><span class="hljs-tag">                &gt;</span>登录&lt;/el-button<br>              &gt;<br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-divider</span>&gt;</span>社交账号直接登录<span class="hljs-tag">&lt;/<span class="hljs-name">el-divider</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span>&gt;</span>微信<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span>&gt;</span>QQ<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span>&gt;</span>GitHub<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span>&gt;</span>Gitee<span class="hljs-tag">&lt;/<span class="hljs-name">el-button</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>          <span class="hljs-tag">&lt;/<span class="hljs-name">el-form</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;login-contain&quot;</span> <span class="hljs-attr">v-else</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>注册<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">el-form</span></span><br><span class="hljs-tag">            <span class="hljs-attr">:model</span>=<span class="hljs-string">&quot;loginForm&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">status-icon</span></span><br><span class="hljs-tag">            <span class="hljs-attr">:rules</span>=<span class="hljs-string">&quot;rules&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">ref</span>=<span class="hljs-string">&quot;loginForm&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">label-width</span>=<span class="hljs-string">&quot;100px&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;login-form&quot;</span></span><br><span class="hljs-tag">            <span class="hljs-attr">:selfUpdate</span>=<span class="hljs-string">&quot;true&quot;</span></span><br><span class="hljs-tag">          &gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;账号&quot;</span> <span class="hljs-attr">prop</span>=<span class="hljs-string">&quot;username&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-input</span> <span class="hljs-attr">v-model.number</span>=<span class="hljs-string">&quot;loginForm.username&quot;</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">el-input</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;密码&quot;</span> <span class="hljs-attr">prop</span>=<span class="hljs-string">&quot;password&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-input</span></span><br><span class="hljs-tag">                <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;password&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">v-model</span>=<span class="hljs-string">&quot;loginForm.password&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">autocomplete</span>=<span class="hljs-string">&quot;off&quot;</span></span><br><span class="hljs-tag">              &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">el-input</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">label</span>=<span class="hljs-string">&quot;确认密码&quot;</span> <span class="hljs-attr">key</span>=<span class="hljs-string">&quot;checkPass&quot;</span> <span class="hljs-attr">prop</span>=<span class="hljs-string">&quot;checkPass&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-input</span></span><br><span class="hljs-tag">                <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;password&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">v-model</span>=<span class="hljs-string">&quot;loginForm.checkPass&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">autocomplete</span>=<span class="hljs-string">&quot;off&quot;</span></span><br><span class="hljs-tag">              &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">el-input</span>&gt;</span><br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>            <span class="hljs-tag">&lt;<span class="hljs-name">el-form-item</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;text-align: center&quot;</span>&gt;</span><br>              <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span></span><br><span class="hljs-tag">                <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 40%&quot;</span></span><br><span class="hljs-tag">                <span class="hljs-attr">type</span>=<span class="hljs-string">&quot;primary&quot;</span></span><br><span class="hljs-tag">                @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;registerSubmitForm(&#x27;loginForm&#x27;)&quot;</span></span><br><span class="hljs-tag">                &gt;</span>提交&lt;/el-button<br>              &gt;<br>            <span class="hljs-tag">&lt;/<span class="hljs-name">el-form-item</span>&gt;</span><br>          <span class="hljs-tag">&lt;/<span class="hljs-name">el-form</span>&gt;</span><br>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;small-box&quot;</span> <span class="hljs-attr">:class</span>=<span class="hljs-string">&quot;&#123; active: isLogin &#125;&quot;</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;small-contain&quot;</span> <span class="hljs-attr">v-if</span>=<span class="hljs-string">&quot;isLogin&quot;</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;stitle&quot;</span>&gt;</span>你好，朋友!<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;scontent&quot;</span>&gt;</span>开始注册，和我们一起旅行<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 60%&quot;</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;changeType&quot;</span> <span class="hljs-attr">round</span></span><br><span class="hljs-tag">            &gt;</span>注册&lt;/el-button<br>          &gt;<br>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;small-contain&quot;</span> <span class="hljs-attr">v-else</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;stitle&quot;</span>&gt;</span>欢迎回来!<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">class</span>=<span class="hljs-string">&quot;scontent&quot;</span>&gt;</span>与我们保持联系，请登录你的账户<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span><br>          <span class="hljs-tag">&lt;<span class="hljs-name">el-button</span> <span class="hljs-attr">style</span>=<span class="hljs-string">&quot;width: 60%&quot;</span> @<span class="hljs-attr">click</span>=<span class="hljs-string">&quot;changeType&quot;</span> <span class="hljs-attr">round</span></span><br><span class="hljs-tag">            &gt;</span>登录&lt;/el-button<br>          &gt;<br>        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br>  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">template</span>&gt;</span><br></code></pre></div></td></tr></table></figure>

<p><img src="/./images/90711640-23CD-478f-B5C9-2089D716075E.gif" srcset="/img/loading.gif" lazyload alt="注册功能"></p>
<p>完美解决</p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p>因为 v-if 在两个相同表单或组件且没有 <code>key</code> 标识唯一性的情况下，会复用已有元素而不是从头开始渲染</p>
<h3 id="demo-地址"><a href="#demo-地址" class="headerlink" title="demo 地址"></a>demo 地址</h3><!-- [login-register-demo](https://gitee.com/Robbinweb/login-register-demo) -->

<p><a href="https://gitee.com/Robbinweb/login-register-demo" target="_blank">login-register-demo</a></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/Vue-js/">Vue.js</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/Vue-js/">#Vue.js</a>
                    
                      <a class="hover-with-bg" href="/tags/ElementUI/">#ElementUI</a>
                    
                      <a class="hover-with-bg" href="/tags/v-if/">#v-if</a>
                    
                      <a class="hover-with-bg" href="/tags/el-form-item/">#el-form-item</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均采用 <a target="_blank" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" rel="nofollow noopener noopener">CC BY-SA 4.0 协议</a> ，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2022/04/15/article-13/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">Express生成器快速搭建web服务器</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2022/03/08/article-11/">
                        <span class="hidden-mobile">还不曾去过倒悬山</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
              <!-- Comments -->
              <article class="comments" id="comments" lazyload>
                
                  
                
                
  <div id="valine"></div>
  <script type="text/javascript">
    Fluid.utils.loadComments('#valine', function() {
      Fluid.utils.createScript('https://cdn.jsdelivr.net/npm/valine@1/dist/Valine.min.js', function() {
        var options = Object.assign(
          {"appId":"A6A3KekcB19LfYQfObiJlDAu-gzGzoHsz","appKey":"h5J0Jt6wCaR3HtH5I0brXmRk","path":"window.location.pathname","placeholder":null,"avatar":"retro","meta":["nick","mail","link"],"requiredFields":[],"pageSize":10,"lang":"zh-CN","highlight":false,"recordIP":false,"serverURLs":"","emojiCDN":null,"emojiMaps":null,"enableQQ":false},
          {
            el: "#valine",
            path: window.location.pathname
          }
        )
        new Valine(options);
        Fluid.utils.waitElementVisible('#valine .vcontent', () => {
          Fluid.plugins.initFancyBox('#valine .vcontent img:not(.vemoji)');
        })
      });
    });
  </script>
  <noscript>Please enable JavaScript to view the comments</noscript>


              </article>
            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->

  <div class="col-lg-7 mx-auto nopadding-x-md">
    <div class="container custom post-custom mx-auto">
      <div style="display: flex;align-items: center;flex-wrap: wrap;flex-direction: row;justify-content: flex-start;"> <img src="https://octodex.github.com/images/jetpacktocat.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> <img src="https://octodex.github.com/images/jetpacktocat.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> <img src="https://octodex.github.com/images/jetpacktocat.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> <img src="https://octodex.github.com/images/jetpacktocat.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> <img src="https://octodex.github.com/images/jetpacktocat.png" srcset="/img/loading.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> </div>
    </div>
  </div>


    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> <div style="font-size: 0.85rem"> <span id="timeDate">载入天数...</span> <span id="times">载入时分秒...</span> <script src="/js/duration.js"></script> </div> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- LeanCloud 统计PV -->
        <span id="leancloud-site-pv-container" style="display: none">
            总访问量 
            <span id="leancloud-site-pv"></span>
             次
          </span>
      
      
        <!-- LeanCloud 统计UV -->
        <span id="leancloud-site-uv-container" style="display: none">
            总访客数 
            <span id="leancloud-site-uv"></span>
             人
          </span>
      

    
  </div>


  
  <!-- 备案信息 -->
  <div class="beian">
    <span>
      <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow noopener">
        京ICP证123456号
      </a>
    </span>
    
      
        <span>
          <a
            href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=12345678"
            rel="nofollow noopener"
            class="beian-police"
            target="_blank"
          >
            
              <span style="visibility: hidden; width: 0">|</span>
              <img src="/img/police_beian.png" srcset="/img/loading.gif" lazyload alt="police-icon"/>
            
            <span>京公网安备12345678号</span>
          </a>
        </span>
      
    
  </div>


  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  <script  src="/js/local-search.js" ></script>



  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  
    <script  src="https://cdn.jsdelivr.net/npm/tocbot@4/dist/tocbot.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3/dist/jquery.fancybox.min.js" ></script>
  
  
    <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4/anchor.min.js" ></script>
  
  
    <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js" ></script>
  




  <script defer src="/js/leancloud.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2/lib/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var title = document.getElementById('subtitle').title;
      
        typing(title);
      
    })(window, document);
  </script>












  
    <!-- Baidu Analytics -->
    <script defer>
      var _hmt = _hmt || [];
      (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b2ef8b4e438bfbfa9667837d1124fb6c";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
  

  

  

  

  

  





<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>


</body>
</html>
